package com.open.thinks.todo.system.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.open.thinks.todo.system.dao.impl.SQLDao;
import com.open.thinks.todo.system.domain.Task;
import com.open.thinks.todo.system.domain.helper.TaskStatus;

@Service
public class TaskService {

	@Resource
	SQLDao sqlDao;

	public List<Task> getTasks(TaskStatus taskStatus) {
		if (taskStatus == null) {
			return sqlDao.query4SingleTable(Task.class, "select * from tasks");
		}
		return sqlDao.query4SingleTable(Task.class, "select * from tasks where status=?", taskStatus);
	}

	public Task getTaskById(String task_id) {
		return sqlDao.load(Task.class, task_id);
	}

	public void delete(Task task) {
		sqlDao.remove(task);
	}

	public void store(Task task) {
		sqlDao.persist(task);
	}

	public void update(Task task) {
		sqlDao.merge(task);
	}
}
